<?php

class user_setting_model extends CI_Model {

	function get_info(){
		
		$user_id=$this->session->userdata('user_id');
		$this->db->where('user_id',$user_id);
		$query = $this->db->get('user_setting');
		if($query->num_rows==0){
			return false;
		}
		elseif($query->num_rows==1){
			return $query->result();
		}
		
		
	}
	
	function get_user_setting_info($user_id){
		$this->db->where('user_id',$user_id);
		$query = $this->db->get('user_setting');
		if($query->num_rows == 1)
		{
			return $query->row();
		}
	}
	
	function createBysavePhoto($photo_path){
		$new_insert_data = array(
			'user_id' => $this->session->userdata('user_id'),
			'photo_path' =>base_url() . $photo_path,										
		);
		$insert = $this->db->insert('user_setting', $new_insert_data);
		return $insert;
	}
	
	function update_photo_path($photo_path)
	{
		$data=array('photo_path'=>base_url() . $photo_path);
		$this->db->where('user_id',$this->session->userdata('user_id'));
		$query=$this->db->update('user_setting', $data);
		return $query;
	}
	
	function update_avatar($avatar_path)
	{
		$data=array('photo_path'=> $avatar_path);
		$this->db->where('user_id',$this->session->userdata('user_id'));
		$query=$this->db->update('user_setting', $data);
		return $query;
	}
	
	//保存用户设置
	function save_setting(){
		$data=array(
					'n_name'=>$_POST['n_name'],
					'birthday'=> $_POST['birthday'],
					'photo_path'=>$_POST['photo_path'],
					'company'=> $_POST['company'],
					'university'=>$_POST['university'],
					'phone'=>$_POST['mobile']
		);
		$this->db->where('user_id',$this->session->userdata('user_id'));
		
		$query=$this->db->update('user_setting',$data);
		return $query;	
	}
	
	//创建用户设置
	function create_setting(){
		$data=array(
					'user_id'=>$this->session->userdata('user_id'),
					'n_name'=>$_POST['n_name'],
					'birthday'=> $_POST['birthday'],
					'photo_path'=>$_POST['photo_path'],
					'company'=> $_POST['company'],
					'university'=>$_POST['university'],
					'phone'=>$_POST['mobile']
		);
		$query=$this->db->insert('user_setting', $data); 
		return $query;
	}
}